home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / T / TE32K Folder / TE32K Demo / windows.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-10  |  18.0 KB  |  939 lines  |  [TEXT/KAHL]

  1. #include "TE32K.h"
  2. #include <stdio.h>
  3.  
  4.  
  5. #define    INDENT    5
  6.  
  7. extern    WindowPtr        theWPtr;
  8. extern    TE32KHandle        theTEH32K;
  9. extern    ControlHandle    theVScroll,theHScroll;
  10. extern    Cursor            editCursor,waitCursor;
  11. extern    char            changed;
  12. extern    SFReply            mySFReply;
  13. extern    int                defaultFont,defaultFontSize;
  14.  
  15.  
  16. SetUpCursors()
  17. {
  18. CursHandle    hCurs;
  19.     
  20.     hCurs = GetCursor(iBeamCursor);
  21.     editCursor = **hCurs;
  22.     
  23.     hCurs = GetCursor(watchCursor);
  24.     waitCursor = **hCurs;
  25. }
  26.  
  27.  
  28.  
  29. DoMouseDown(theEvent)
  30. EventRecord    *theEvent;
  31. {
  32. WindowPtr    whichWindow;
  33. int            windowCode;
  34.  
  35.     windowCode = FindWindow(theEvent->where,&whichWindow);
  36.     
  37.     switch (windowCode = FindWindow(theEvent->where,&whichWindow)) 
  38.     {
  39.         case inMenuBar:
  40.             DoCommand(MenuSelect(theEvent->where));
  41.             break;
  42.             
  43.         case inSysWindow:
  44.             SystemClick(theEvent,whichWindow);
  45.             break;
  46.             
  47.         case inContent:
  48.             if (whichWindow != FrontWindow())
  49.                 SelectWindow(whichWindow);
  50.             
  51.             else if (IsOurWindow(whichWindow))
  52.                 DoContent(whichWindow,theEvent);
  53.             
  54.             break;
  55.         
  56.         case inDrag:
  57.             if (whichWindow != FrontWindow())
  58.                 SelectWindow(whichWindow);
  59.             
  60.             else if (IsOurWindow(whichWindow))
  61.                 DoDrag(whichWindow,theEvent);
  62.             
  63.             break;
  64.             
  65.         case inGrow:
  66.             if (whichWindow != FrontWindow())
  67.                 SelectWindow(whichWindow);
  68.             
  69.             else if (IsOurWindow(whichWindow))
  70.                 DoGrow(whichWindow,theEvent);
  71.             
  72.             break;
  73.         
  74.         case inZoomIn:
  75.         case inZoomOut:
  76.             if (whichWindow != FrontWindow())
  77.                 SelectWindow(whichWindow);
  78.             
  79.             else if (IsOurWindow(whichWindow) && TrackBox(whichWindow,theEvent->where,windowCode))
  80.                 DoZoom(whichWindow,windowCode);
  81.             
  82.             break;
  83.         
  84.         case inGoAway:
  85.             if (whichWindow != FrontWindow())
  86.                 SelectWindow(whichWindow);
  87.             
  88.             else if (IsOurWindow(whichWindow) && TrackGoAway(whichWindow,theEvent->where))
  89.                 DoCloseWindow(whichWindow);
  90.             
  91.             break;
  92.     }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. IsOurWindow(whichWindow)
  101. WindowPtr    whichWindow;
  102. {
  103.     if (theWPtr && whichWindow == theWPtr)
  104.         return(TRUE);
  105.     else
  106.         return(FALSE);
  107. }
  108.  
  109.  
  110.  
  111. DoActivateDeactivate(whichWindow,adFlag)
  112. WindowPtr    whichWindow;char    adFlag;
  113. {
  114. Rect            tempRect;
  115. GrafPtr            oldPort;
  116.  
  117.     if (whichWindow == theWPtr)
  118.     {
  119.         GetPort(&oldPort);
  120.         SetPort(whichWindow);
  121.         
  122.         if (adFlag)
  123.         {
  124.             HiliteControl(theVScroll,0);
  125.             HiliteControl(theHScroll,0);
  126.             TE32KActivate(theTEH32K);
  127.         }
  128.         else
  129.         {
  130.             HiliteControl(theVScroll,255);
  131.             HiliteControl(theHScroll,255);
  132.             TE32KDeactivate(theTEH32K);
  133.         }
  134.         
  135.         DrawGrowIcon(whichWindow);
  136.         
  137.         SetPort(oldPort);
  138.         
  139.         return(TRUE);
  140.     }
  141.     
  142.     else
  143.         return(FALSE);
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. DoCloseWindow(whichWindow)
  152. WindowPtr    whichWindow;
  153. {
  154. int        userChoice;
  155.  
  156.     if (theWPtr && whichWindow==theWPtr)
  157.     {
  158.         if (changed)
  159.         {
  160.             userChoice = YesNoCancel("Save changes?",3);
  161.             
  162.             if (userChoice == 3)
  163.                 return(FALSE);
  164.             
  165.             else if (userChoice == 1 && !SaveTextFile(theTEH32K,&mySFReply))
  166.                 return(FALSE);
  167.         }        
  168.         
  169.         if (theVScroll) DisposeControl(theVScroll);
  170.         if (theHScroll) DisposeControl(theHScroll);
  171.         if (theTEH32K) TE32KDispose(theTEH32K);
  172.         if (theWPtr) DisposeWindow(theWPtr);
  173.         
  174.         theWPtr = 0L;
  175.         theTEH32K = 0L;
  176.         theVScroll = 0L;
  177.         theHScroll = 0L;
  178.         
  179.         return(TRUE);
  180.     }
  181.     
  182.     else
  183.         return(FALSE);
  184. }
  185.  
  186.  
  187.  
  188. DoGrow(whichWindow,theEvent)
  189. WindowPtr    whichWindow;EventRecord    *theEvent;
  190. {
  191. Rect            tempRect;
  192. long            newSize;
  193. GrafPtr            oldPort;
  194.  
  195.     if (theWPtr && whichWindow==theWPtr)
  196.     {
  197.         SetRect(&tempRect,100,50,32767,32767);
  198.         newSize = GrowWindow(whichWindow,theEvent->where,&tempRect);
  199.         SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),0xff);
  200.         tempRect = whichWindow->portRect;
  201.         GetPort(&oldPort);
  202.         SetPort(whichWindow);
  203.         EraseRect(&tempRect);
  204.         InvalRect(&tempRect);
  205.         
  206.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  207.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  208.         
  209.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  210.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  211.         
  212.         AdjustForResizedWindow();
  213.         
  214.         SetPort(oldPort);
  215.         
  216.         return(TRUE);
  217.     }
  218.     
  219.     else
  220.         return(FALSE);
  221. }
  222.  
  223.  
  224.  
  225.  
  226. DoZoom(whichWindow,windowCode)
  227. WindowPtr    whichWindow;int windowCode;
  228. {
  229. Rect            tempRect;
  230. GrafPtr            oldPort;
  231.  
  232.     if (theWPtr && whichWindow==theWPtr)
  233.     {
  234.         GetPort(&oldPort);
  235.         SetPort(whichWindow);
  236.         
  237.         tempRect = whichWindow->portRect;
  238.         EraseRect(&tempRect);
  239.         
  240.         ZoomWindow(whichWindow, windowCode, 0);
  241.         
  242.         tempRect = whichWindow->portRect;
  243.         EraseRect(&tempRect);
  244.         
  245.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  246.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  247.         
  248.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  249.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  250.         
  251.         AdjustForResizedWindow();
  252.         
  253.         tempRect = whichWindow->portRect;
  254.         InvalRect(&tempRect);
  255.         
  256.         SetPort(oldPort);
  257.         
  258.         return(TRUE);
  259.     }
  260.     
  261.     else
  262.         return(FALSE);
  263. }
  264.  
  265.  
  266.  
  267. DoDrag(whichWindow,theEvent)
  268. WindowPtr    whichWindow;EventRecord    *theEvent;
  269. {
  270. Rect            tempRect;
  271.  
  272.     if (theWPtr && whichWindow == theWPtr)
  273.     {
  274.         SetRect(&tempRect,screenBits.bounds.left+10,screenBits.bounds.top+25,screenBits.bounds.right-10,screenBits.bounds.bottom-25);
  275.         DragWindow(whichWindow,theEvent->where,&tempRect);
  276.         return(TRUE);
  277.     }
  278.     
  279.     else
  280.         return(FALSE);
  281. }
  282.  
  283.  
  284.  
  285.  
  286. AdjustScrollBar()
  287. {
  288. int        ctlVal,screenLines,numLines,oldVal;
  289.  
  290.     ctlVal = ((*theTEH32K)->viewRect.top - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight;
  291.     screenLines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  292.     numLines = (**theTEH32K).nLines;
  293.     
  294.     if (ctlVal > numLines-screenLines)
  295.         SetCtlMax(theVScroll,ctlVal);
  296.     else
  297.         SetCtlMax(theVScroll,(numLines-screenLines > 0) ? numLines-screenLines : 0);
  298.     
  299.     oldVal = GetCtlValue(theVScroll);
  300.     
  301.     if (oldVal != ctlVal)
  302.         SetCtlValue(theVScroll,ctlVal);
  303.     
  304.     
  305.     
  306.     ctlVal = ((*theTEH32K)->viewRect.left - (*theTEH32K)->destRect.left)/(*theTEH32K)->lineHeight;
  307.     numLines = GetCtlMax(theHScroll);
  308.     
  309.     if (ctlVal < 0)
  310.         ctlVal = 0;
  311.     else if (ctlVal > numLines)
  312.         ctlVal = numLines;
  313.     
  314.     oldVal = GetCtlValue(theHScroll);
  315.     
  316.     if (oldVal != ctlVal)
  317.         SetCtlValue(theHScroll,ctlVal);
  318. }
  319.  
  320.  
  321.  
  322. AdjustForResizedWindow()
  323. {
  324. LongRect    tempLongRect;
  325. Rect        tempRect;
  326.  
  327.     SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  328.     tempRect.bottom = tempRect.top + ((tempRect.bottom - tempRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  329.     
  330.     RectToLongRect(&tempRect,&((*theTEH32K)->viewRect));
  331.     
  332.     RectToLongRect(&tempRect,&((*theTEH32K)->destRect));
  333.     (*theTEH32K)->destRect.top -= (long) GetCtlValue(theVScroll)*(*theTEH32K)->lineHeight;
  334.     (*theTEH32K)->destRect.left -= (long) GetCtlValue(theHScroll)*(*theTEH32K)->lineHeight;
  335.     
  336.     (**theTEH32K).destRect.right -= 10;
  337.     
  338.     TE32KFromScrap();
  339.     
  340.     SetCursor(&waitCursor);
  341.     TE32KCalText(theTEH32K);
  342.     InitCursor();
  343.     
  344.     AdjustScrollBar();
  345. }
  346.  
  347.  
  348.  
  349. pascal void myScrollProc(theControl, theCode)
  350. ControlHandle    theControl;int    theCode;
  351. {
  352. long        scrollAmt,lines,numLines;
  353. int            controlMax,controlMin,controlVal;
  354. RgnHandle    updateRgn;
  355.     
  356.     if (theVScroll && theControl==theVScroll)
  357.     {
  358.         controlMax = GetCtlMax(theControl);
  359.         controlMin = GetCtlMin(theControl);
  360.         controlVal = GetCtlValue(theControl);
  361.         
  362.         updateRgn = NewRgn();
  363.         
  364.         switch (theCode) 
  365.         {
  366.             case inUpButton:
  367.                 if (controlVal > controlMin)
  368.                 {
  369.                     SetCtlValue(theControl,controlVal-1);
  370.                     
  371.                     TE32KScroll(0L,(long) (**theTEH32K).lineHeight,theTEH32K);
  372.                 }
  373.                 
  374.                 break;
  375.                 
  376.             case inDownButton: 
  377.                 if (controlVal < controlMax)
  378.                 {
  379.                     SetCtlValue(theControl,controlVal+1);
  380.                     
  381.                     TE32KScroll(0L,(long) -(**theTEH32K).lineHeight,theTEH32K);
  382.                 }
  383.                 
  384.                 break;
  385.     
  386.             case inPageUp: 
  387.                 if (controlVal > controlMin)
  388.                 {
  389.                     lines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  390.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  391.                     SetCtlValue(theControl,controlVal-scrollAmt);
  392.                     TE32KScroll(0L,(long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  393.                 }
  394.                 
  395.                 break;
  396.     
  397.             case inPageDown: 
  398.                 if (controlVal < controlMax)
  399.                 {
  400.                     lines = ((**theTEH32K).viewRect.bottom - (**theTEH32K).viewRect.top)/(**theTEH32K).lineHeight;
  401.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  402.                     SetCtlValue(theControl,controlVal+scrollAmt);
  403.                     TE32KScroll(0L,(long) ((long) -scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  404.                 }
  405.                 
  406.                 break;
  407.         }
  408.         
  409.         AdjustScrollBar();
  410.         
  411.         DisposeRgn(updateRgn);
  412.     }
  413.     
  414.     else if (theHScroll && theControl==theHScroll)
  415.     {
  416.         controlMax = GetCtlMax(theControl);
  417.         controlMin = GetCtlMin(theControl);
  418.         controlVal = GetCtlValue(theControl);
  419.         
  420.         updateRgn = NewRgn();
  421.         
  422.         switch (theCode) 
  423.         {
  424.             case inUpButton:
  425.                 if (controlVal > controlMin)
  426.                 {
  427.                     SetCtlValue(theControl,controlVal-1);
  428.                     
  429.                     TE32KScroll((long) (**theTEH32K).lineHeight,0L,theTEH32K);
  430.                 }
  431.                 
  432.                 break;
  433.                 
  434.             case inDownButton: 
  435.                 if (controlVal < controlMax)
  436.                 {
  437.                     SetCtlValue(theControl,controlVal+1);
  438.                     
  439.                     TE32KScroll((long) -(**theTEH32K).lineHeight,0L,theTEH32K);
  440.                 }
  441.                 
  442.                 break;
  443.     
  444.             case inPageUp: 
  445.                 if (controlVal > controlMin)
  446.                 {
  447.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  448.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  449.                     SetCtlValue(theControl,controlVal-scrollAmt);
  450.                     TE32KScroll((long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  451.                 }
  452.                 
  453.                 break;
  454.     
  455.             case inPageDown: 
  456.                 if (controlVal < controlMax)
  457.                 {
  458.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  459.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  460.                     SetCtlValue(theControl,controlVal+scrollAmt);
  461.                     TE32KScroll((long) -((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  462.                 }
  463.                 
  464.                 break;
  465.         }
  466.         
  467.         AdjustScrollBar();
  468.         
  469.         DisposeRgn(updateRgn);
  470.     }
  471. }
  472.  
  473.  
  474.  
  475.  
  476.  
  477. DoContent(whichWindow,theEvent)
  478. WindowPtr    whichWindow;EventRecord    *theEvent;
  479. {
  480. GrafPtr            oldPort;
  481. ControlHandle    whichControl;
  482. int                cntlCode,ctlVal,oldVal;
  483. Rect            tempRect;
  484.  
  485.     if (theWPtr && whichWindow==theWPtr)
  486.     {
  487.         GetPort(&oldPort);
  488.         SetPort(whichWindow);
  489.         
  490.         LongRectToRect(&((**theTEH32K).viewRect),&tempRect);
  491.         
  492.         GlobalToLocal(&(theEvent->where));
  493.         
  494.         cntlCode = FindControl(theEvent->where,whichWindow,&whichControl);
  495.         
  496.         if (theVScroll && whichControl == theVScroll && cntlCode != 0)
  497.         {
  498.             if (cntlCode == inThumb)
  499.             {
  500.                 oldVal = GetCtlValue(whichControl);
  501.                 
  502.                 TrackControl(whichControl,theEvent->where,0L);
  503.                 
  504.                 TE32KScroll(0L,(long) ((oldVal - GetCtlValue(whichControl)) * (**theTEH32K).lineHeight),theTEH32K);
  505.             }
  506.             
  507.             else
  508.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  509.         }
  510.         
  511.         else if (theHScroll && whichControl == theHScroll && cntlCode != 0)
  512.         {
  513.             if (cntlCode == inThumb)
  514.             {
  515.                 oldVal = GetCtlValue(whichControl);
  516.                 
  517.                 TrackControl(whichControl,theEvent->where,0L);
  518.                 
  519.                 TE32KScroll((long) ((oldVal - GetCtlValue(whichControl)) * (**theTEH32K).lineHeight),0L,theTEH32K);
  520.             }
  521.             
  522.             else
  523.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  524.         }
  525.         
  526.         else if (PtInRect(theEvent->where,&tempRect))
  527.         {
  528.             if (theEvent->modifiers & shiftKey)
  529.                 TE32KClick(theEvent->where,TRUE,theTEH32K);
  530.             else
  531.                 TE32KClick(theEvent->where,FALSE,theTEH32K);
  532.         }
  533.         
  534.         SetPort(oldPort);
  535.         
  536.         return(TRUE);
  537.     }
  538.     
  539.     else
  540.         return(FALSE);
  541. }
  542.  
  543.  
  544.  
  545.  
  546. UpdateWindow(whichWindow)
  547. WindowPtr    whichWindow;
  548. {
  549. GrafPtr            oldPort;
  550. Rect            tempRect;
  551. LongRect        tempLongRect;
  552. RgnHandle        updateRgn;
  553.  
  554.     if (whichWindow != theWPtr)
  555.         return(FALSE);
  556.  
  557.     GetPort(&oldPort);
  558.     SetPort(whichWindow);
  559.     
  560.     PenNormal();
  561.     
  562.     BeginUpdate(whichWindow);
  563.     
  564.     tempRect = whichWindow->portRect;
  565.     EraseRect(&tempRect);
  566.     
  567.     if (whichWindow == theWPtr)
  568.     {
  569.         DrawGrowIcon(whichWindow);
  570.         DrawControls(whichWindow);
  571.         
  572.         updateRgn = ((WindowPeek) theWPtr)->updateRgn;
  573.         
  574.         tempLongRect.left = (**updateRgn).rgnBBox.left;
  575.         tempLongRect.top = (**updateRgn).rgnBBox.top;
  576.         tempLongRect.right = (**updateRgn).rgnBBox.right;
  577.         tempLongRect.bottom = (**updateRgn).rgnBBox.bottom;
  578.         
  579.         RectToLongRect(&tempRect,&tempLongRect);
  580.         TE32KUpdate(&tempLongRect,theTEH32K);
  581.     }
  582.     
  583.     EndUpdate(whichWindow);
  584.     
  585.     SetPort(oldPort);
  586.     
  587.     return(TRUE);
  588. }
  589.  
  590.  
  591.  
  592.  
  593.  
  594. void MyClicker()
  595. {
  596. int            controlMax,controlMin,controlVal,lineHeight;
  597. Rect        viewRect;
  598. Point        mousePoint;
  599. RgnHandle    saveClip;
  600. long        hDelta,vDelta;
  601.  
  602.     LongRectToRect(&((**theTEH32K).viewRect),&viewRect);
  603.     lineHeight = (**theTEH32K).lineHeight;
  604.  
  605.     hDelta = 0L;
  606.     vDelta = 0L;
  607.     
  608.     GetMouse(&mousePoint);
  609.     
  610.     if (!PtInRect(mousePoint,&viewRect))
  611.     {
  612.         controlMax = GetCtlMax(theVScroll);
  613.         controlMin = GetCtlMin(theVScroll);
  614.         controlVal = GetCtlValue(theVScroll);
  615.         
  616.         if (mousePoint.v>viewRect.bottom && controlVal<controlMax)
  617.         {
  618.             vDelta = -lineHeight;
  619.             SetCtlValue(theVScroll,controlVal+1);
  620.         }
  621.         
  622.         else if (mousePoint.v<viewRect.top && controlVal>controlMin)
  623.         {
  624.             vDelta = lineHeight;
  625.             SetCtlValue(theVScroll,controlVal-1);
  626.         }
  627.         
  628.         controlMax = GetCtlMax(theHScroll);
  629.         controlMin = GetCtlMin(theHScroll);
  630.         controlVal = GetCtlValue(theHScroll);
  631.         
  632.         if (mousePoint.h>viewRect.right && controlVal<controlMax)
  633.         {
  634.             hDelta = -lineHeight;
  635.             SetCtlValue(theHScroll,controlVal+1);
  636.         }
  637.         
  638.         else if (mousePoint.h<viewRect.left && controlVal>controlMin)
  639.         {
  640.             hDelta = lineHeight;
  641.             SetCtlValue(theHScroll,controlVal-1);
  642.         }
  643.     }
  644.     
  645.     if (hDelta || vDelta)
  646.     {
  647.         saveClip = NewRgn();
  648.         GetClip(saveClip);
  649.         ClipRect(&(theWPtr->portRect));
  650.         
  651.         TE32KScroll(hDelta,vDelta,theTEH32K);
  652.         
  653.         SetClip(saveClip);
  654.         DisposeRgn(saveClip);
  655.     }
  656. }
  657.  
  658.  
  659.  
  660.  
  661. void MyClickLoop()
  662. {
  663.     asm
  664.     {
  665.         movem.l        d1-d7/a0-a6,-(sp)
  666.         jsr            MyClicker
  667.         movem.l        (sp)+,d1-d7/a0-a6
  668.         moveq.l        #1,d0
  669.         rts
  670.     }
  671. }
  672.  
  673.  
  674.  
  675.  
  676. DoShowWindow()
  677. {
  678. Rect            tempRect;
  679. FontInfo        theFontInfo;
  680. LongRect        tempLongRect;
  681.  
  682.     if (theWPtr)
  683.         SelectWindow(theWPtr);
  684.         
  685.     else
  686.     {
  687.         SetRect(&tempRect,20,40,500,320);
  688.         
  689.         theWPtr = NewWindow (0L,&tempRect,"\pUntitled",TRUE,zoomDocProc,(WindowPtr) -1L,TRUE,0L);
  690.         if (StripAddress(theWPtr)==0L)
  691.         {
  692.             ErrorAlert("Insufficient memory to open window");
  693.             return;
  694.         }
  695.         
  696.         SetPort(theWPtr);
  697.         
  698.         TextFont(defaultFont);
  699.         TextSize(defaultFontSize);
  700.         TextFace(0);
  701.         TextMode(srcCopy);
  702.         
  703.         GetFontInfo(&theFontInfo);
  704.         
  705.         SetRect(&tempRect,(theWPtr)->portRect.right-15,(theWPtr)->portRect.top-1,(theWPtr)->portRect.right+1,(theWPtr)->portRect.bottom-14);
  706.         theVScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,0,scrollBarProc,0L);
  707.         
  708.         if (StripAddress(theVScroll)==0L)
  709.         {
  710.             DisposeWindow(theWPtr);
  711.             theWPtr = 0L;
  712.             theVScroll = 0L;
  713.             ErrorAlert("Insufficient memory to open edit record");
  714.             return;
  715.         }
  716.         
  717.         SetRect(&tempRect,(theWPtr)->portRect.left-1,(theWPtr)->portRect.bottom+1-16,(theWPtr)->portRect.right-14,(theWPtr)->portRect.bottom+1);
  718.         theHScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,255,scrollBarProc,0L);
  719.         
  720.         if (StripAddress(theVScroll)==0L)
  721.         {
  722.             DisposeWindow(theWPtr);
  723.             DisposeControl(theVScroll);
  724.             theWPtr = 0L;
  725.             theVScroll = 0L;
  726.             theHScroll = 0L;
  727.             ErrorAlert("Insufficient memory to open edit record");
  728.             return;
  729.         }
  730.         
  731.         SetRect(&(tempRect),(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  732.         RectToLongRect(&tempRect,&tempLongRect);
  733.         theTEH32K = TE32KNew(&tempLongRect,&tempLongRect);
  734.     
  735.         if (StripAddress(theTEH32K)==0L)
  736.         {
  737.             DisposeControl(theVScroll);
  738.             DisposeControl(theHScroll);
  739.             DisposeWindow(theWPtr);
  740.             theWPtr = 0L;
  741.             theVScroll = 0L;
  742.             theHScroll = 0L;
  743.             ErrorAlert("Insufficient memory to open edit record");
  744.             return;
  745.         }
  746.         
  747.         (**theTEH32K).destRect.right -= 10;
  748.         
  749.         TE32KFromScrap();
  750.         
  751.         (*theTEH32K)->destRect.bottom = (*theTEH32K)->destRect.top + (((*theTEH32K)->destRect.bottom - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  752.         (*theTEH32K)->viewRect.bottom = (*theTEH32K)->viewRect.top + (((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  753.         
  754.         (**theTEH32K).clikLoop = (ProcPtr) MyClickLoop;
  755.         
  756.         changed = FALSE;
  757.         
  758.         mySFReply.good = FALSE;
  759.     }
  760. }
  761.  
  762.  
  763.  
  764. DoKey(theChar)
  765. unsigned char    theChar;
  766. {
  767.     if (theWPtr && theWPtr == FrontWindow())
  768.     {
  769.         TE32KKey(theChar,theTEH32K);
  770.         
  771.         TE32KSelView(theTEH32K);
  772.         
  773.         changed = TRUE;
  774.         
  775.         AdjustScrollBar();
  776.         
  777.         return(TRUE);
  778.     }
  779.     
  780.     else
  781.         return(FALSE);
  782. }
  783.  
  784.  
  785. DoIdle()
  786. {
  787.     if (theWPtr && theWPtr == FrontWindow())
  788.     {
  789.         TE32KIdle(theTEH32K);
  790.         
  791.         return(TRUE);
  792.     }
  793.     
  794.     else
  795.         return(FALSE);
  796. }
  797.  
  798.  
  799.  
  800.  
  801.  
  802. MaintainCursor()
  803. {
  804. Point        pt;
  805. GrafPtr        oldPort;
  806. Rect        tempRect;
  807.  
  808.     if (theWPtr && FrontWindow() == theWPtr)
  809.     {
  810.         GetPort(&oldPort);
  811.         SetPort(theWPtr);
  812.         
  813.         SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  814.         
  815.         GetMouse(&pt);
  816.         
  817.         if (PtInRect(pt,&tempRect))
  818.             SetCursor(&editCursor);
  819.         
  820.         else
  821.             SetCursor(&arrow);
  822.         
  823.         return(TRUE);
  824.         
  825.         SetPort(oldPort);
  826.     }
  827.     
  828.     return(FALSE);
  829. }
  830.  
  831.  
  832.  
  833.  
  834. DoCut()
  835. {
  836.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  837.     {
  838.         SetCursor(&waitCursor);
  839.         TE32KCut(theTEH32K);
  840.         ZeroScrap();
  841.         TE32KToScrap();
  842.         InitCursor();
  843.         
  844.         changed = TRUE;
  845.         
  846.         TE32KSelView(theTEH32K);
  847.         AdjustScrollBar();
  848.         
  849.         return(TRUE);
  850.     }
  851.     
  852.     else
  853.         return(FALSE);
  854. }
  855.  
  856.  
  857.  
  858. DoCopy()
  859. {
  860.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  861.     {
  862.         SetCursor(&waitCursor);
  863.         TE32KCopy(theTEH32K);
  864.         ZeroScrap();
  865.         TE32KToScrap();
  866.         InitCursor();
  867.         
  868.         return(TRUE);
  869.     }
  870.     
  871.     else
  872.         return(FALSE);
  873. }
  874.  
  875.  
  876.  
  877.  
  878. DoPaste()
  879. {
  880.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  881.     {
  882.         SetCursor(&waitCursor);
  883.         TE32KFromScrap();
  884.         TE32KPaste(theTEH32K);
  885.         InitCursor();
  886.         
  887.         changed = TRUE;
  888.         
  889.         TE32KSelView(theTEH32K);
  890.         AdjustScrollBar();
  891.         
  892.         return(TRUE);
  893.     }
  894.     
  895.     else
  896.         return(FALSE);
  897. }
  898.  
  899.  
  900.  
  901.  
  902.  
  903. DoClear()
  904. {
  905.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  906.     {
  907.         SetCursor(&waitCursor);
  908.         TE32KDelete(theTEH32K);
  909.         InitCursor();
  910.         
  911.         changed = TRUE;
  912.         
  913.         TE32KSelView(theTEH32K);
  914.         AdjustScrollBar();
  915.         
  916.         return(TRUE);
  917.     }
  918.     
  919.     else
  920.         return(FALSE);
  921. }
  922.  
  923.  
  924.  
  925. DoSelectAll()
  926. {
  927.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  928.     {
  929.         SetCursor(&waitCursor);
  930.         TE32KSetSelect(0L,(**theTEH32K).teLength,theTEH32K);
  931.         AdjustScrollBar();
  932.         InitCursor();
  933.         
  934.         return(TRUE);
  935.     }
  936.     
  937.     else
  938.         return(FALSE);
  939. }